package com.zb.order.controller;


import com.zb.annotation.SystemLog;
import com.zb.constant.OperationLogModuleType;
import com.zb.constant.OperationLogType;
import com.zb.entity.SelectVo;
import com.zb.order.service.ConWorkClientStrategyService;
import com.zb.result.Result;
import com.zb.service.ZjWorkClientStrategyService;
import com.zb.utils.TokenUtil;
import com.zb.vo.WorkClientStrategyVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;
import java.util.List;

/**
 * <p>
 * 工单客服分派策略表 前端控制器
 * </p>
 *
 * @author WEN
 * @since 2023-09-27
 */
@Api(tags = "工单客服分配规则类接口")
@RestController
@RequestMapping("/work/client")
public class ZjWorkClientStrategyController {
    @Resource
    private ZjWorkClientStrategyService workClientStrategyService;
    @Resource
    private ConWorkClientStrategyService conWorkClientStrategyService;


    @SystemLog(moduleType = OperationLogModuleType.WORK_ORDER_TYPE, type = OperationLogType.INSERT_UPDATE, remark = "工单管理-工单设置-工单分配策略 - 工单客服分配策略 - 新增或修改工单客服分配规则")
    @ApiOperation("新增或修改工单客服分配规则")
    @PostMapping("/save")
    public Result save(HttpServletRequest request, @RequestBody @Valid WorkClientStrategyVo clientStrategyVo) {
        Long custAccId = TokenUtil.getcustAccIdByToken(request);
        workClientStrategyService.save(custAccId, clientStrategyVo);
        return Result.success(null == clientStrategyVo.getId()? "新增分配客服规则成功" : "修改分配客服规则成功");
    }

    @ApiOperation("获取工单客服分配规则列表")
    @PostMapping("/getList")
    public Result getList(HttpServletRequest request, @RequestBody SelectVo selectVo) {
        Long custAccId = TokenUtil.getcustAccIdByToken(request);
        return Result.success("获取工单客服分配规则列表成功").data(conWorkClientStrategyService.getList(custAccId, selectVo));
    }

    @ApiOperation("根据ID获取工单客服分配规则详情")
    @GetMapping("/getDetail/{id}")
    public Result getDetail(@PathVariable @ApiParam(value = "客服分配规则ID", required = true) Long id) {
        return Result.success("获取工单客服分配规则详情成功").data("row", workClientStrategyService.getDetail(id));
    }

    @SystemLog(moduleType = OperationLogModuleType.WORK_ORDER_TYPE, type = OperationLogType.UPDATE, remark = "工单管理-工单设置-工单分配策略 - 工单客服分配策略 - 批量启用或禁用工单客服分配规则")
    @ApiOperation("批量启用或禁用工单客服分配规则")
    @PutMapping("/disable")
    public Result disable(@RequestParam @ApiParam(value = "工单客服分配规则状态：false-启用，true-禁用", required = true, example = "false") boolean status,
                          @RequestBody @ApiParam(value = "工单客服分配规则ID", required = true) List<Long> idList) {
        workClientStrategyService.updateDisableBatchById(idList, status);
        return Result.success(status? "禁用客服分配规则成功" : "启用客服分配规则成功");
    }

    @SystemLog(moduleType = OperationLogModuleType.WORK_ORDER_TYPE, type = OperationLogType.DELETE, remark = "工单管理-工单设置-工单分配策略 - 工单客服分配策略 - 批量删除工单客服分配规则")
    @ApiOperation("批量删除工单客服分配规则")
    @DeleteMapping("/delete")
    public Result delete(@RequestBody @ApiParam(value = "工单客服分配规则ID", required = true) List<Long> idList) {
        workClientStrategyService.deleteBatchById(idList);
        return Result.success("删除客服分配规则成功");
    }

}
